package cz.salixsoft.bugreporter.adapter.mantis;

import cz.salixsoft.bugreporter.Severity;
import java.math.BigInteger;

/**
 * Converts severity from interface values to mantis values.
 *
 * @author Vrbenský Milan
 * @version 1.0 @created 01-II-2012 15:59:53
 */
class MantisSeverityConverter {

    public final BigInteger FEATURE = new BigInteger("10");
    public final BigInteger TRIVIAL = new BigInteger("20");
    public final BigInteger TEXT = new BigInteger("30");
    public final BigInteger TWEAK = new BigInteger("40");
    public final BigInteger LOW = new BigInteger("50");
    public final BigInteger MINOR = new BigInteger("60");
    public final BigInteger MAJOR = new BigInteger("70");
    public final BigInteger CRASH = new BigInteger("80");
    public final BigInteger BLOCK = new BigInteger("90");



    /**
     * Default severity.
     */
    protected BigInteger defaultSeverity;

    /**
     * Constructor. Sets the default severity to MEDIUM.
     */
    public MantisSeverityConverter() {
        setDefaultSeverity(Severity.MEDIUM);
    }

    /**
     * Return priority corresponds values in Mantis application.
     *
     * @param severity Severity of issue.
     *
     * @return BigInteger priority code from Mantis application
     */
    public BigInteger getSeverity(Severity severity) {
        BigInteger mantisSeverity;

        switch (severity) {
            case HIGH:
                mantisSeverity = this.MAJOR;
                break;
            case MEDIUM:
                mantisSeverity = this.MINOR;
                break;
            case LOW:
                mantisSeverity = this.LOW;
                break;
            default:
                mantisSeverity = defaultSeverity;
                break;
        }

        return mantisSeverity;
    }

    /**
     * Sets the default severity. Cannot be set to null or Severity.NOT_DEFINED
     * value.
     *
     * @param severity Default severity of bugs.
     */
    public final void setDefaultSeverity(Severity severity) {
        if (severity.equals(Severity.NOT_DEFINED)) {
            throw new IllegalArgumentException("Default severity cannot be set do NOT_DEFINED.");
        }

        defaultSeverity = getSeverity(severity);
    }
}
